package tool.dialog;


import javax.swing.JFrame;
import javax.swing.JLabel;

import annotations.MainConstructor;

import tool.MainConstructorNotFoundException;
import tool.classloader.ClassNotSupportedException;

@Deprecated
public class JExceludedClassParametersConstructorDialog extends JConstructorDialog{

	private static final long serialVersionUID = -4983278305918836020L;
	/**rappresenta la lista di parametri che non devono essere introdotti nel dialog.
	 * 
	 */
	protected Class<?>[] parametersTypeExcluded;

	public JExceludedClassParametersConstructorDialog(JFrame parent,Class<?> _toconstruct,Class<?> ...parameterstypeexcluded) throws MainConstructorNotFoundException {
		super(parent, _toconstruct);
		this.parametersTypeExcluded=parameterstypeexcluded;
	}
	
	@Override
	protected void populateParameterPanelList()throws ClassNotSupportedException {
		MainConstructor annotation=this.getMainConstructor().getAnnotation(MainConstructor.class);
		Class<?>[] params=this.getMainConstructor().getParameterTypes();
		Class<?> param=null;
		boolean toExclude=false;
		for (int i=0;i<params.length;i++){
			param=params[i];
			for (int j=0;j<this.parametersTypeExcluded.length;j++){
				if (param.equals(this.parametersTypeExcluded[j])){
					toExclude=true;
					break;
				}
			}
			if (toExclude){
				toExclude=false;
				break;
			}
			if ((!param.isPrimitive())&&(!param.equals(String.class))){
				this.getParameterPanelList().removeAllElements();
				throw new ClassNotSupportedException(param);
			}
			this.getParameterPanelList().add(new JParameterPanel(new JLabel(annotation.descriptions()[i]),this.retrieveCorrectTextField(param)));
		}
	}
	
	

}
